//
//  JWDetailTopView.m
//  JWMovie
//
//  Created by Jorn.Wu on 15/7/20.
//  Copyright (c) 2015年 Jorn.Wu. All rights reserved.
//

#import "JWDetailTopView.h"
#import "JWMovieDetailModel.h"
#import "UIImageView+WebCache.h"

@interface JWDetailTopView ()
@property (nonatomic, strong) UIImageView *image;
@property (nonatomic, strong) UILabel *movieTitle;
@property (nonatomic, strong) UILabel *directors;
@property (nonatomic, strong) UILabel *actors;
@property (nonatomic, strong) UILabel *type;
@property (nonatomic, strong) UILabel *myRelease;

@end

@implementation JWDetailTopView

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
 
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
//        NSLog(@"-----------initWithNibName-----");
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        imageView.backgroundColor = [UIColor grayColor];
        [self.view addSubview:imageView];
        _image = imageView;
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        titleLabel.textColor = [UIColor orangeColor];
        titleLabel.font = [UIFont systemFontOfSize:17];
//        titleLabel.backgroundColor = [UIColor grayColor];
        [self.view addSubview:titleLabel];
        _movieTitle = titleLabel;
        
        UILabel *directorsLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        directorsLabel.textColor = [UIColor whiteColor];
        directorsLabel.font = [UIFont systemFontOfSize:13];
//        directorsLabel.backgroundColor = [UIColor grayColor];
        [self.view addSubview:directorsLabel];
        _directors = directorsLabel;
        
        UILabel *actorsLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        actorsLabel.textColor = [UIColor whiteColor];
        actorsLabel.font = [UIFont systemFontOfSize:13];
//        actorsLabel.backgroundColor = [UIColor grayColor];
        [self.view addSubview:actorsLabel];
        _actors = actorsLabel;
        
        UILabel *typeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        typeLabel.textColor = [UIColor whiteColor];
        typeLabel.font = [UIFont systemFontOfSize:13];
//        typeLabel.backgroundColor = [UIColor grayColor];
        [self.view addSubview:typeLabel];
        _type = typeLabel;
        
        UILabel *releaseLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        releaseLabel.textColor = [UIColor whiteColor];
        releaseLabel.font = [UIFont systemFontOfSize:13];
//        releaseLabel.backgroundColor = [UIColor grayColor];
        [self.view addSubview:releaseLabel];
        _myRelease = releaseLabel;
    }
    
    return self;
}

- (void)setMovieDetailModel:(JWMovieDetailModel *)movieDetailModel{
//    NSLog(@"-----------setMovieDetailModel-----");
    _movieDetailModel = movieDetailModel;
    
    NSString *urlStr = _movieDetailModel.image;
    [self.image sd_setImageWithURL:[NSURL URLWithString:urlStr]];
    
    self.movieTitle.text = _movieDetailModel.titleCn;

//    导演表
    NSMutableString *str0 = [NSMutableString stringWithFormat:@"导演："];
    
    for (int i = 0; i < _movieDetailModel.directors.count; i++) {
        if (i!= _movieDetailModel.directors.count - 1) {
            NSString *tStr = _movieDetailModel.directors[i];
            [str0 appendFormat:@"%@、",tStr];
        }else {
            NSString *tStr = _movieDetailModel.directors[i];
            [str0 appendFormat:@"%@",tStr];
        }
        
    }
    
    self.directors.text = str0;

//    演员表
    NSMutableString *str1 = [NSMutableString stringWithFormat:@"演员："];
    
    for (int i = 0; i < _movieDetailModel.actors.count; i++) {
        if (i!= _movieDetailModel.actors.count - 1) {
            NSString *tStr = _movieDetailModel.actors[i];
            [str1 appendFormat:@"%@、",tStr];
        }else {
            NSString *tStr = _movieDetailModel.actors[i];
            [str1 appendFormat:@"%@",tStr];
        }
        
    }

    self.actors.text = str1;
    
//    类型
    NSMutableString *str2 = [NSMutableString stringWithFormat:@"类型："];
    
    for (int i = 0; i < _movieDetailModel.type.count; i++) {
        if (i!= _movieDetailModel.type.count - 1) {
            NSString *tStr = _movieDetailModel.type[i];
            [str2 appendFormat:@"%@、",tStr];
        }else {
            NSString *tStr = _movieDetailModel.type[i];
            [str2 appendFormat:@"%@",tStr];
        }
        
    }
    
    self.type.text = str2;
    
//    地区和年份
    
    NSString *str3 = [_movieDetailModel.myRelease objectForKey:@"location"];
    NSString *str4 = [_movieDetailModel.myRelease objectForKey:@"date"];
    
    self.myRelease.text = [NSString  stringWithFormat:@"%@ %@",str3,str4];
  
}

- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
//    NSLog(@"-----------viewWillLayoutSubviews-----");

    self.image.frame = CGRectMake(5, 5, 115, 130);

    self.movieTitle.frame = CGRectMake(125, 5, 245, 30);

    self.directors.frame = CGRectMake(125, 35, 245, 25);

    self.actors.frame = CGRectMake(125, 60, 245, 25);
    
    self.type.frame = CGRectMake(125, 85, 245, 25);
    
    self.myRelease.frame = CGRectMake(125, 110, 245, 25);

    
}








- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
